var app = getApp(), imgArray1 = [], siteinfo = require("../../../siteinfo.js");

Page({
    data: {
        addmuban: !0,
        textarea: !0,
        edit: !1,
        textarea_info: ""
    },
    onLoad: function(t) {
        console.log(t);
        var e = this;
        if (app.setNavigationBarColor(this), e.setData({
            events: t,
            url: wx.getStorageSync("url")
        }), console.log(imgArray1), app.util.request({
            url: "entry/wxapp/url",
            cachetime: "0",
            success: function(t) {
                console.log("这是网址"), console.log(t), e.setData({
                    url: t.data
                });
            }
        }), app.getUserInfo(function(t) {
            console.log(t), e.setData({
                userInfo: t
            });
        }), "" != t.imgs) {
            console.log("这是有图片");
            var o = t.imgs.split(",");
            for (var a in o) imgArray1.push(o[a]);
            e.setData({
                textarea: !0,
                edit: !0,
                imgArray1: imgArray1
            });
        }
        "" != t.content && (console.log("这是有内容"), e.setData({
            textarea: !1,
            edit: !1,
            imgArray1: imgArray1,
            textarea_info: app.convertHtmlToText(t.content)
        }));
    },
    textarea: function(t) {
        this.setData({
            textarea: !1,
            addmuban: !0
        });
    },
    botxianshi: function() {
        this.setData({
            addmuban: !1
        });
    },
    img_array: function(t) {
        var o = this;
        o.setData({
            addmuban: !0
        });
        var a = siteinfo.siteroot;
        wx.chooseImage({
            count: 9,
            sizeType: [ "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(t) {
                wx.showToast({
                    icon: "loading",
                    title: "正在上传"
                });
                var e = t.tempFilePaths;
                o.uploadimg({
                    url: a + "?i=" + o.data.userInfo.uniacid + "&c=entry&a=wxapp&do=Upload&m=zh_gjhdbm",
                    path: e
                });
            }
        });
    },
    uploadimg: function(t) {
        var e = this, o = t.i ? t.i : 0, a = t.success ? t.success : 0, i = t.fail ? t.fail : 0;
        wx.uploadFile({
            url: t.url,
            filePath: t.path[o],
            name: "upfile",
            formData: null,
            success: function(t) {
                "" != t.data ? (a++, imgArray1.push(t.data), 0 < imgArray1.length ? e.setData({
                    imgArray1: imgArray1,
                    edit: !0
                }) : e.setData({
                    edit: !1
                }), console.log("上传商家轮播图时候提交的图片数组", imgArray1)) : wx.showToast({
                    icon: "loading",
                    title: "请重试"
                });
            },
            fail: function(t) {
                i++;
            },
            complete: function() {
                ++o == t.path.length ? (e.setData({
                    images: t.path
                }), wx.hideToast()) : (t.i = o, t.success = a, t.fail = i, e.uploadimg(t));
            }
        });
    },
    delete_text: function(t) {
        this.setData({
            textarea: !0
        });
    },
    delete: function(t) {
        console.log(t);
        var e = t.currentTarget.dataset.index;
        Array.prototype.indexOf = function(t) {
            for (var e = 0; e < this.length; e++) if (this[e] == t) return e;
            return -1;
        }, Array.prototype.remove = function(t) {
            var e = this.indexOf(t);
            -1 < e && this.splice(e, 1);
        }, imgArray1.remove(imgArray1[e]), this.setData({
            imgArray1: imgArray1
        }), 0 == imgArray1.length && this.setData({
            edit: !1
        });
    },
    botcancel: function() {
        this.setData({
            addmuban: !0
        });
    },
    textarea_info: function(t) {
        console.log(t), this.setData({
            textarea_info: t.detail.value
        });
    },
    botnext: function() {
        wx.navigateTo({
            url: "fabusuccess"
        });
    },
    formSubmit: function(t) {
        console.log(t);
        var e = this, a = t.detail.formId, o = e.data.events;
        imgArray1 = imgArray1;
        var i = e.data.userInfo, n = i.id, s = o.title, r = o.uplogo, l = o.start_time, c = o.end_time;
        if ("在线报名" == o.mode) var g = 1; else g = 3;
        var u = o.array;
        u = "线上活动" == u ? 1 : 2;
        var d = o.bminfo, m = e.data.textarea_info;
        m = m.replace("\n", "↵");
        var p = o.classification, f = wx.getStorageSync("city"), y = o.address, h = o.coordinates, _ = imgArray1.join(","), x = wx.getStorageSync("actype"), v = o.link_tel, A = o.sponsor;
        if (1 == wx.getStorageSync("platform").city_open) var w = o.city; else w = "";
        var b = o.samll_price, D = o.hx_code, S = o.activity_id;
        console.log("用户id为" + n), console.log("标题为" + s), console.log("logo为" + r), console.log("开始时间为" + l), 
        console.log("结束时间为" + c), console.log("活动场景为" + u), console.log("报名信息为" + d), console.log("活动详情为" + m), 
        console.log("活动分类为" + p), console.log("活动城市为" + f), console.log("活动地址为" + y), console.log("活动地址经纬度为" + h), 
        console.log("活动图片为" + _), console.log("联系电话为" + v), console.log("票券信息为"), console.log(x), 
        console.log("主办方姓名为" + A), console.log("所属城市为" + w), console.log("核销码为" + D), console.log("活动id为" + S), 
        null != S ? app.util.request({
            url: "entry/wxapp/SaveActivity",
            cachetime: "0",
            method: "POST",
            data: {
                activity_id: S,
                user_id: n,
                title: s,
                logo: r,
                start_time: l,
                end_time: c,
                bm_start: l,
                bm_end: c,
                join_type: g,
                activity_type: u,
                content: m,
                type_id: p,
                cityname: w,
                address: y,
                bm_info: d,
                coordinates: h,
                hd_imgs: _,
                link_tel: v,
                sponsor: A,
                sponser: i.name,
                zd_money: o.zd_money,
                hx_code: D
            },
            success: function(t) {
                console.log("这是提交报名结果"), console.log(t), 1 == t.data && (wx.showToast({
                    title: "修改成功"
                }), setTimeout(function() {
                    wx.redirectTo({
                        url: "fabusuccess"
                    });
                }, 1500));
            }
        }) : app.util.request({
            url: "entry/wxapp/SaveActivity",
            cachetime: "0",
            method: "POST",
            data: {
                user_id: n,
                title: s,
                logo: r,
                start_time: l,
                end_time: c,
                bm_start: l,
                bm_end: c,
                join_type: g,
                activity_type: u,
                content: m,
                type_id: p,
                cityname: w,
                address: y,
                bm_info: d,
                coordinates: h,
                hd_imgs: _,
                ticket: JSON.stringify(x),
                link_tel: v,
                sponsor: A,
                sponser: i.name,
                zd_money: b,
                hx_code: D
            },
            success: function(t) {
                console.log("这是提交报名结果"), console.log(t);
                var e = t.data, o = wx.getStorageSync("userInfo").openid;
                app.util.request({
                    url: "entry/wxapp/Message2",
                    cachetime: "0",
                    data: {
                        form_id: a,
                        openid: o,
                        activity_id: e
                    },
                    success: function(t) {
                        console.log("发送模板消息"), console.log(t);
                    }
                }), wx.redirectTo({
                    url: "fabusuccess"
                });
            }
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {
        0 < imgArray1.length && imgArray1.splice(0, imgArray1.length);
    },
    onPullDownRefresh: function() {},
    onReachBottom: function() {}
});